/*
 * Copyright (c) Extreme Vision Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __HTTP_CLIENT_H__
#define __HTTP_CLIENT_H__

#include <string>
#include <vector>
#include <map>
#include <glog/logging.h>

using namespace std;

namespace ev
{

    class CHttpClient
    {
    public:
        explicit CHttpClient();
        ~CHttpClient();

        /**
         * @brief http get method using curl
         * @param[in] strUrl: http url
         * @param[in] map_headers: headers content wrapped in map format
         * @param[in] strRsp: http response content
         * @return int:  -1 http get failed, 0 http get succeed
         */

        int http_get(const string &strUrl, const map<string, string> &map_headers, string &strRsp);
        /**
         * @brief http put method using curl
         * @param[in] strUrl: http url
         * @param[in] map_headers: headers content wrapped in map format
         * @param[in] strParmas: params for curl
         * @param[in] strRsp: http response content
         * @return int:  -1 http get failed, 0 http get succeed
         */
        int http_put(const string &strUrl, const map<string, string> &map_headers,
                     const string &strParams, string &strRsp);

        /**
         * @brief http post method using curl
         * @param[in] strUrl: http url
         * @param[in] http_post_headers_map: headers content wrapped in map format
         * @param[in] strParmas: params for curl
         * @param[in] strRsp: http response content
         * @return int:  -1 http get failed, 0 http get succeed
         */
        int http_post(const string &strUrl, const map<string, string> &http_post_headers_map,
                      const string &strParams, string &strRsp);

        /**
         * @brief http delete method using curl
         * @param[in] strUrl: http url
         * @param[in] map_headers: headers content wrapped in map format
         * @param[in] strRsp: http response content
         * @return int:  -1 http get failed, 0 http get succeed
         */
        int http_delete(const string &strUrl, const map<string, string> &map_headers, string &strRsp);

        /**
         * @brief http post file method using curl
         * @param[in] strUrl: http url
         * @param[in] v_info: post file info
         * @param[in] v_file: post file
         * @param[in] strRsp: http response content
         * @return int:  -1 http get failed, 0 http get succeed
         */
        int htt_post_file(const string &strUrl, const vector<pair<string, string>> &v_info,
                          const vector<pair<string, string>> &v_file, string &strRsp);

    private:
        static size_t on_write_data(void *buffer, size_t size, size_t nmemb, void *lpVoid);
    };

} // end namespace ev
#endif